<?php
	include "../public/commom/config.php";
	include "../public/commom/commom.php";
	
	$brandCondition = isset($_GET["brand_id"]) ? "WHERE id='{$_GET["brand_id"]}'" : "";
?>

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>品牌</title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
		<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
		<link rel="stylesheet" type="text/css" href="public/css/index.css"/>
	</head>

	<body>
		<?php include "public/commom/header.php"; ?>
		<div id="brand">
				<?php
					$bsql = "SELECT * FROM brand {$brandCondition}";
					
					$bresult = mysqli_query($conn, $bsql);
					
					while($row = mysqli_fetch_assoc($bresult)) {
						echo "<div class='brand-title'>
								<h4>" . $row["name"] . "</h4>
							</div>";
							
						$shopCondition = isset($_GET["brand_id"]) ? $_GET["brand_id"] : $row["id"];
						
						$ssql = "SELECT shop.*, area.name aname, store.name sname FROM shop LEFT JOIN area ON (shop.area_id = area.id) LEFT JOIN store ON (shop.store_id = store.id) WHERE shop.brand_id = {$shopCondition}";
						
						$sresult = mysqli_query($conn, $ssql);
						
						while($row = mysqli_fetch_assoc($sresult)) {
						?>
						
							<div class='brand-shop'>
								<div class='brand-shop-left'>
									<a href="shopdetails.php?shop_id=<?php echo $row["id"]; ?>"><img src="<?php echo $imgPath . $row["img"]; ?>" width='100px'/></a>
								</div>
								<div class='brand-shop-right'>
									<div>
										<h6><?php echo $row["name"]; ?></h6>
										<p><b>￥<?php echo $row["price"]; ?></b>&nbsp;&nbsp;&nbsp;销量：<?php echo $row["sales"]; ?>&nbsp;&nbsp;&nbsp;<?php echo $row["aname"]; ?></p>
										<p>库存：<?php echo $row["inventory"]; ?></p>
										<p><?php echo $row["sname"]; ?><a href='store.php?store_id=<?php echo $row["store_id"]; ?>'>进店</a></p>
									</div>
								</div>
							</div>
							
						<?php		
						}
					}
					
					mysqli_close($conn);
					
				?>
		</div>
	</body>

</html>